package com.whh.db;

import com.jfinal.kit.Prop;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.dialect.SqlServerDialect;
import com.jfinal.plugin.druid.DruidPlugin;

import java.util.Date;

public class InitMySql {
    private static InitMySql single = new InitMySql();

    private InitMySql() {

    }

    public static InitMySql getInstance(){
        if(single == null) {
            single = new InitMySql();
        }
        return single;
    }

    public void start() {
        System.out.println("MySql start ...");
        Date start = new Date();
        Prop prop = PropKit.use("jdbc-mysql.properties");
        DruidPlugin druidPlugin = new DruidPlugin(prop.get("jdbcUrl"), prop.get("user"), prop.get("password"), prop.get("driver"));
        druidPlugin.start();
        ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);
        arp.setDialect(new SqlServerDialect());
        arp.addMapping("pjws_bak", PjwsModel.class);
        arp.addMapping("xf", XingFaModel.class);
        arp.start();
        System.out.println("MySql connect OK...used time : " + ((new Date()).getTime()-start.getTime()) + " 毫秒");
    }
}
